package com.service;

import java.util.List;

import com.dao.CommentDao;
import com.dao.IdeaDao;
import com.entity.Comment;
import com.entity.Idea;
import com.util.PageHelp;

public class IdeaService {
	
	private IdeaDao id=new IdeaDao();
	private CommentDao cd=new CommentDao();
	
	public PageHelp<Idea> findIdeaByPage(int pageNum) {
		PageHelp<Idea> page=new PageHelp<Idea>(5,id.getCount(),pageNum);
		return id.findByPage(page);
	}
	
	public void saveIdea(Idea i) {
		id.saveIdea(i);
		
	}
	
	public Idea findIdeaById(String ideaId) {
		return id.findIdeaById(ideaId);
	}

	

	public boolean editIdeaById(Idea i) {
		return id.updateIdeaById(i);
	}

	public boolean saveMsgFormIdeaToComment(Comment c) {
		return cd.saveMsgFromIdeaToComment(c);
	}


	public boolean delIdeaById(String ideaid) {
		boolean s1= cd.deByIdeaid(ideaid);
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		boolean s2=id.delIdeaById(ideaid);
		if(s1==true && s2==true){
			return true;
		}
		return false;
	}

	public List<Comment> findAllComment() {
		return cd.findAllCommenttoIdea();
	}

	public boolean delIdeaSayById(String id) {
		boolean s1= cd.delById(id);
		if(s1==true){
			return true;
		}
		return false;
	}


}
